#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <queue>
#include <numeric>

using namespace std;

class Solution {
public:
    vector<int> missingRolls(vector<int>& rolls, int mean, int n) {
        /* 计算待返回数组总和 */
        int rollsSum = accumulate(rolls.begin(), rolls.end(), 0);
        int retSum = mean * (rolls.size() + n) - rollsSum;

        vector<int> ret{};
        if (retSum > 6 * n || retSum < 1 * n) {
            return ret;
        }

        /* 先定义填充模式，然后填充数字 */
        GetRoll(ret, retSum, n);

        return ret;
    }

    void GetRoll(vector<int>& ret, int retSum, int n)
    {
        while (n != 0) {
            if (retSum - 6 >= (n - 1) * 1) {
                ret.push_back(6);
                retSum -= 6;
            } else if (retSum - 5 >= (n - 1) * 1) {
                ret.push_back(5);
                retSum -= 5;
            } else if (retSum - 4 >= (n - 1) * 1) {
                ret.push_back(4);
                retSum -= 4;
            } else if (retSum - 3 >= (n - 1) * 1) {
                ret.push_back(3);
                retSum -= 3;
            } else if (retSum - 2 >= (n - 1) * 1) {
                ret.push_back(2);
                retSum -= 2;
            } else {
                ret.push_back(1);
                retSum -= 1;   
            }
            n -= 1;
        }

        return;
    }
};


int main()
{   
    Solution s;
    vector<int> vt{3,2,4,3};
    vector<int> ret = s.missingRolls(vt, 4, 2);

    for (auto num : ret) {
        cout << num << " ";
    }
    cout << endl;
    return 0;
}